package com.zz.bsea.web.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCBasic {

	
	public static Connection getConnection() {
		Connection conn =null;
		
			try {
				Class.forName("com.mysql.cj.jdbc.Driver");
				//java10是数据库的名字
				String url="jdbc:mysql://localhost:3306/java11?useSSL=false&serverTimezone=Asia/Shanghai";
				//登录数据库用户名
				String username="root";
				//登录数据库密码
				String pwd="hykjc3F2020";
				conn = DriverManager.getConnection(url,username,pwd);
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
			
	
		
		return conn;
		
	}
	
	
	public static void closeConn(Statement st,ResultSet rs,Connection conn) {
		if(rs!=null) {
			try {
				rs.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		if(st!=null) {
			try {
				st.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		if( conn!=null) {
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	}
}
